package com.woniu.aimd.controller;

import com.woniu.aimd.pojo.entity.WcqQuestions;
import com.woniu.aimd.pojo.entity.Wronganswerquestion;
import com.woniu.aimd.pojo.entity.Wrongchoicequestion;
import com.woniu.aimd.service.impl.WchoixequestionImpl;
import com.woniu.aimd.service.impl.MychoicequestionImpl;
import com.woniu.aimd.service.impl.WanswerquestionImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

//@CrossOrigin(origins = "*")
@RestController
@RequestMapping("questions")
public class InsertquestionController {
    @Autowired
    private WchoixequestionImpl wchoixequestionimp;
    @Autowired
    private WanswerquestionImpl wanswerquestionimp;
    @Autowired
    private MychoicequestionImpl mychoicequestionimp;
    @PostMapping("insertChoiceQuestion")
    public void wchoixequestion(@RequestBody List<WcqQuestions> allwrong) {
        Wrongchoicequestion wrongchoicequestion = new Wrongchoicequestion();
     for (int i=0;i<allwrong.size();i++){
         wrongchoicequestion.setHeader(allwrong.get(i).getHeader());
         wrongchoicequestion.setRightanswer(allwrong.get(i).getRightanswer());
         wrongchoicequestion.setChoiceA(allwrong.get(i).getAnswerschoice().get(0));
         wrongchoicequestion.setChoiceB(allwrong.get(i).getAnswerschoice().get(1));
         wrongchoicequestion.setChoiceC(allwrong.get(i).getAnswerschoice().get(2));
         wrongchoicequestion.setChoiceD(allwrong.get(i).getAnswerschoice().get(3));
         wrongchoicequestion.setStatus(1);
         wrongchoicequestion.setUser_id(allwrong.get(i).getUser_id());
         wrongchoicequestion.setPrompt(allwrong.get(i).getPrompt());
         wchoixequestionimp.wchoixequestion(wrongchoicequestion);
     }
    }
    @PostMapping("insertAnswerQuestion")
    public void wanswerquestion(@RequestBody Wronganswerquestion wronganswerquestion) {
            wronganswerquestion.setStatus(0);
            wanswerquestionimp.wanswerquestion(wronganswerquestion);
    }
    //打包60分一下解答题
    @PostMapping("insertWAnswerQuestions")
    public void insertWAnswerQuestions(@RequestBody List<Wronganswerquestion> wronganswerquestions) {
        for (int i = 0; i < wronganswerquestions.size(); i++) {
            Wronganswerquestion wronganswerquestion = new Wronganswerquestion();
            wronganswerquestion.setHeader(wronganswerquestions.get(i).getHeader());
            wronganswerquestion.setRightanswer(wronganswerquestions.get(i).getRightanswer());
            wronganswerquestion.setStatus(1);
            wronganswerquestion.setUser_id(wronganswerquestions.get(i).getUser_id());
            wronganswerquestion.setPrompt(wronganswerquestions.get(i).getPrompt());
            wanswerquestionimp.wanswerquestion(wronganswerquestion);
        }
    }
    @PostMapping("insertmychoicequestion")
    public void mychoicequestion(@RequestBody WcqQuestions wcqQuestions ) {
        Wrongchoicequestion wrongchoicequestion = new Wrongchoicequestion();
        wrongchoicequestion.setHeader(wcqQuestions.getHeader());
        wrongchoicequestion.setRightanswer(wcqQuestions.getRightanswer());
        wrongchoicequestion.setChoiceA(wcqQuestions.getAnswerschoice().get(0));
        wrongchoicequestion.setChoiceB(wcqQuestions.getAnswerschoice().get(1));
        wrongchoicequestion.setChoiceC(wcqQuestions.getAnswerschoice().get(2));
        wrongchoicequestion.setChoiceD(wcqQuestions.getAnswerschoice().get(3));
        wrongchoicequestion.setStatus(0);
        wrongchoicequestion.setUser_id(wcqQuestions.getUser_id());
        wrongchoicequestion.setPrompt(wcqQuestions.getPrompt());
        mychoicequestionimp.mychoicequestion(wrongchoicequestion);
    }
}
